package com.oocl.sc.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.sc.service.SmenuService;
import com.oocl.sc.service.impl.SmenuServiceImpl;

public class LoadAllMenu extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static SmenuService smenuService = new SmenuServiceImpl();
	private static String menus = null;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String json = getMenus();
		response.setCharacterEncoding("utf-8");
		response.getWriter().write(json);
	}
	
	public static String getMenus(){
		if (menus == null) {
			menus = smenuService.loadAllMenuToJSON();
			System.out.println("Find menu from DB");
		}else{
			System.out.println("Find menu from cached.");
		}
		return menus;
	}

}
